/*
 * Copyright @ 苏州瑞云信息技术有限公司 All rights reserved.
 */
package cn.com.recloud.bbs.service.impl;

import cn.com.recloud.bbs.dao.MetaoptionDao;
import cn.com.recloud.bbs.dao.MetaoptionsetDao;
import cn.com.recloud.bbs.entity.metaoption;
import cn.com.recloud.bbs.entity.metaoptionset;
import cn.com.recloud.bbs.service.MetaoptionService;
import cn.com.recloud.core.constant.SysConstant;
import cn.com.recloud.one.spring.service.impl.BaseServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author herry
 * @date 2020-06-08
 */
@Service
public class MetaoptionServiceImpl extends BaseServiceImpl<MetaoptionDao, metaoption> implements MetaoptionService {

    @Autowired
    private MetaoptionsetDao metaoptionsetDao;

    @Autowired
    private MetaoptionDao metaoptionDao;

    @Override
    public List<metaoption> selectMetaOptionBySetName(String name) {
        //1. 通过名称查询选项集
        metaoptionset optionSet = metaoptionsetDao.selectOne(new QueryWrapper<metaoptionset>().lambda().eq(metaoptionset::getName,name).eq(metaoptionset::getStatecode, SysConstant.STATECODE_ENABLE));
        if (null==optionSet) {
            return null;
        }
        //2. 通过选项集ID查询选项集值列表
        List<metaoption> options = metaoptionDao.selectList(new QueryWrapper<metaoption>().lambda().eq(metaoption::getOptionsetid,optionSet.getOptionsetid()).eq(metaoption::getStatecode,SysConstant.STATECODE_ENABLE));
        return options;
    }

    @Override
    public List<metaoption> selectMetaOptionByOptionId(String optionId) {
        //1. 通过选项集值ID查询选项集值
        metaoption option = metaoptionDao.selectOne(new QueryWrapper<metaoption>().lambda().eq(metaoption::getOptionid,optionId).eq(metaoption::getStatecode, SysConstant.STATECODE_ENABLE));
        if (null == option) {
            return null;
        }
        //2. 查询选项集值列表
        List<metaoption> options = metaoptionDao.selectList(new QueryWrapper<metaoption>().lambda().eq(metaoption::getOptionsetid,option.getOptionsetid()).eq(metaoption::getStatecode,SysConstant.STATECODE_ENABLE));
        return options;
    }

    @Override
    public metaoption findMetaOptionBySetNameAndValue(String name,String value) {
        //1. 通过名称查询选项集
        metaoptionset optionSet = metaoptionsetDao.selectOne(new QueryWrapper<metaoptionset>().lambda().eq(metaoptionset::getName,name).eq(metaoptionset::getStatecode, SysConstant.STATECODE_ENABLE));
        if (null==optionSet) {
            return null;
        }
        metaoption option = metaoptionDao.selectOne(new QueryWrapper<metaoption>().lambda().eq(metaoption::getOptionsetid,optionSet.getOptionsetid()).eq(metaoption::getValue,value).eq(metaoption::getStatecode,SysConstant.STATECODE_ENABLE));
        return option;
    }
}
